package test.study.kits.excel.easyexcel._1_read;

import cn.hutool.core.io.resource.ResourceUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.io.InputStream;
import java.util.Date;

@Slf4j
public class _2_indexOrName_read_Test {

    private InputStream istream = ResourceUtil.getStream("");

    @Test
    public void test() {
        EasyExcel.read(istream, IndexOrNameData.class, new MyEventListener())
                .sheet()
                .doRead();
    }

    @Data
    private static class IndexOrNameData {
        @ExcelProperty("姓名")
        private String userName;
        @ExcelProperty("生日")
        private Date birthday;
        @ExcelProperty(index = 3)
        private Double amount;
//        @ExcelIgnore
        private Integer age;
    }

    private class MyEventListener extends AnalysisEventListener<IndexOrNameData> {

        public void invoke(IndexOrNameData rowData, AnalysisContext context) {
            log.info(">>>>>> {}", rowData);
        }

        public void doAfterAllAnalysed(AnalysisContext context) {
            log.info("所有数据解析完成！");
        }
    }
}
